<htm>
	<head>
		<title>ip2city</title>
		<meta charset="utf-8" />
		<script type="text/javascript" src="JKJY.js"></script>
	</head>
	<body>
	ip2city
	<button id="show" onclick="showCity()" default-text="查询城市" processing-text="查询中...">查询城市</button>
	<input type="text" id="ipaddr" placeholder="ip地址, 为空查询当前城市">
	<script>
		function showCity() {
			var ipaddr = document.getElementById('ipaddr');

			if(ipaddr.value.length > 0) {
				JKJY.ip2city(ipaddr.value, function(city, detail){
					console.log(city, detail);
					var text = [detail.country, detail.province, detail.city].join(' ');
					var elm = document.getElementById('show');
					elm.innerHTML = elm.getAttribute('default-text') + ':' + text;
				}, function () {
					var elm = document.getElementById('show');
					elm.innerHTML = elm.getAttribute('processing-text');
				});
			} else {
				JKJY.currentip2city(function(city, detail) {
					console.log(city, detail);
					var text = [detail.country, detail.province, detail.city].join(' ');
					var elm = document.getElementById('show');
					elm.innerHTML = elm.getAttribute('default-text') + ':' + text;
				}, function () {
					var elm = document.getElementById('show');
					elm.innerHTML = elm.getAttribute('processing-text');
				})
			}
		}
	</script>
	</body>
</htm>